package io.osw.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.osw.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.osw.modules.sys.entity.TblSchoolEntity;
import io.osw.modules.sys.service.TblSchoolService;
import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;



/**
 * 校区表
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-05 15:32:37
 */
@RestController
@RequestMapping("sys/tblschool")
public class TblSchoolController extends AbstractController{
    @Autowired
    private TblSchoolService tblSchoolService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tblschool:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblSchoolService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{schoolId}")
    @RequiresPermissions("sys:tblschool:info")
    public R info(@PathVariable("schoolId") Long schoolId){
        TblSchoolEntity tblSchool = tblSchoolService.selectById(schoolId);

        return R.ok().put("tblSchool", tblSchool);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tblschool:save")
    public R save(@RequestBody TblSchoolEntity tblSchool){
        tblSchool.setCreateTime(new Date());
        tblSchool.setCreateBy(getUserId());
        tblSchool.setCompanyId(getUser().getCompanyId());
        tblSchoolService.insert(tblSchool);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tblschool:update")
    public R update(@RequestBody TblSchoolEntity tblSchool){
        ValidatorUtils.validateEntity(tblSchool);
        tblSchool.setUpdateTime(new Date());
        tblSchool.setUpdateBy(getUserId());
        tblSchoolService.updateAllColumnById(tblSchool);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tblschool:delete")
    public R delete(@RequestBody Long[] schoolIds){
        tblSchoolService.deleteBatchIds(Arrays.asList(schoolIds));

        return R.ok();
    }

}
